<?php
require_once('framework/msc-load.php');
require_once('framework/msc-functions.php');


if(isset($_GET['search'])):
    global $db;

    $address_city_name = '';
    $guests = 1;

    if(isset($_GET['address']))
        $address_city_name = $_GET['address'];
    
    if(isset($_GET['start'])){
        $checkin = $_GET['start'];
        $getcheckin=$checkin;
        $dateFormat = explode('/',$checkin);
        $checkin = $dateFormat[2].'-'.$dateFormat[1].'-'.$dateFormat[0];
    }

    if(isset($_GET['end'])){
        $checkout = $_GET['end'];
        $getcheckout=$checkout;
        $dateFormat = explode('/',$checkout);
        $checkout = $dateFormat[2].'-'.$dateFormat[1].'-'.$dateFormat[0];
    }
    
    if(isset($_GET['guests'])){
       (($_GET['guests'] != '4+') ? $guests = $_GET['guests'] : $guests = $_GET['guests_list']); 
    }

    if($address_city_name != '')
        $condition1 = '(`City` LIKE "'.$address_city_name.'" OR `Name` LIKE "'.$address_city_name.'" OR `Address` LIKE "'.$address_city_name.'") AND ';

    $query = 'SELECT ID FROM HOTELS WHERE '.$condition1.' ID IN (SELECT Hotel FROM ROOM_TYPES WHERE `Guests` >= '.$guests.')';
    $result = $db->query($query);

    $hotelsearch=array();    
    if($result):
        while ($row = $result->fetch_assoc()):
            array_push($hotelsearch, array( "ID" => $row['ID']));
        endwhile;
    endif;
    
endif;

?>

<!DOCTYPE HTML>
<html>

<head>
    <title>Search Results - MSC Hotels</title>
   
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta name="keywords" content="" />
    <meta name="description" content="">
    <meta name="author" content="MSC Team">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- GOOGLE FONTS -->
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,600' rel='stylesheet' type='text/css'>
    <!-- /GOOGLE FONTS -->
   
    <link rel="stylesheet" href="assets/css/bootstrap.css">
    <link rel="stylesheet" href="assets/css/font-awesome.css">
    <link rel="stylesheet" href="assets/css/icomoon.css">
    <link rel="stylesheet" href="assets/css/styles.css">
    <script src="assets/js/modernizr.js"></script>
   
</head>

<body>

    <div class="global-wrap">
        <header id="main-header">
            <div class="header-top">
                <div class="container">
                    <div class="row">
                        <div class="col-md-3">
                            <a class="logo" href="index.php">
                                <img src="assets/img/logo-invert.png" alt="Image Alternative text" title="Image Title" />
                            </a>
                        </div>
                        <div class="col-md-5">
                            <h5 class="text-color">NOTICE: This is an experimental project.</h5>
                        </div>
                        <div class="col-md-4">
                            <div class="top-user-area clearfix">
                                <ul class="top-user-area-list list list-horizontal list-border">
                                    <?php if(isRegistered()): ?>
                                        <li class="top-user-area-avatar"><a href="user-profile.php">Hi, <?php echo NameShit(); ?></a></li>
                                        <li><a href="/logout.php">Log Out</a></li>
                                    <?php else: ?>
                                        <li class="top-user-area-avatar"><a>Hi, <?php echo getUserName(); ?></a></li>
                                        <li><a href="/signup.php">Log In</a></li>
                                    <?php endif; ?>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container">
                <div class="nav">
                    <ul class="slimmenu" id="slimmenu">
                        <li><a href="index.php">Home</a></li>
                        <li><a href="listings.php">Hotels</a></li>
                    </ul>
                </div>
            </div>
        </header>

    <div class="global-wrap">
                <div class="container">
            <ul class="breadcrumb">
                <li><a href="index.php">Home</a>
                </li>
                <li><a href="#">Hotels</a>
                </li>
             </ul>
            <div class="mfp-with-anim mfp-hide mfp-dialog mfp-search-dialog" id="search-dialog">
                <h3>Search for Hotel</h3>
                <form action="" method="get">
                    <div class="form-group form-group-lg form-group-icon-left"><i class="fa fa-map-marker input-icon input-icon-highlight"></i>
                        <label>Where are you going?</label>
                        <input class="typehead form-control" value="<?php if(isset($address_city_name) && $address_city_name != ''){ echo $address_city_name;} else echo 'Address, City or Hotel Name'?>" type="text" name="address"/>
                    </div>
                    <div class="input-daterange" data-date-format="dd/mm/yyyy">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="form-group form-group-lg form-group-icon-left"><i class="fa fa-calendar input-icon input-icon-highlight"></i>
                                    <label>Check-in</label>
                                    <input class="form-control" name="start" value="<?php if(isset($checkin)){echo $getcheckin;} else echo "" ;?>"  type="text" />
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group form-group-lg form-group-icon-left"><i class="fa fa-calendar input-icon input-icon-highlight"></i>
                                    <label>Check-out</label>
                                    <input class="form-control" name="end" value="<?php if(isset($checkout)){echo $getcheckout;} else echo "" ;?>" type="text" />
                                </div>
                            </div>
                          <div class="col-md-4">
                                <div class="form-group form-group-lg form-group-select-plus">
                                    <label>Guests</label>
                                    <div class="btn-group btn-group-select-num" data-toggle="buttons">
                                        <label class="btn btn-primary <?php if($guests == 1) echo 'active'; ?>">
                                            <input type="radio" name="guests" value="1" <?php if($guests == 1) echo 'checked'; ?> />1</label>
                                        <label class="btn btn-primary <?php if($guests == 2) echo 'active'; ?>">
                                            <input type="radio" name="guests" value="2" <?php if($guests == 2) echo 'checked'; ?> />2</label>
                                        <label class="btn btn-primary <?php if($guests == 3) echo 'active'; ?>">
                                            <input type="radio" name="guests" value="3" <?php if($guests == 3) echo 'checked'; ?> />3</label>
                                        <label class="btn btn-primary <?php if($guests == 4) echo 'active'; ?>">
                                            <input type="radio" name="guests" value="4" <?php if($guests == 4) echo 'checked'; ?> />4</label>
                                        <label class="btn btn-primary <?php if($guests > 4) echo 'active'; ?>">
                                            <input type="radio" name="guests" value="4+" />4+</label>
                                    </div>
                                    <select class="form-control hidden" name="guests_list">
                                        <option <?php if($guests == 1) echo 'selected="selected"'; ?>>1</option>
                                        <option <?php if($guests == 2) echo 'selected="selected"'; ?>>2</option>
                                        <option <?php if($guests == 3) echo 'selected="selected"'; ?>>3</option>
                                        <option <?php if($guests == 4) echo 'selected="selected"'; ?>>4</option>
                                        <option <?php if($guests == 5) echo 'selected="selected"'; ?>>5</option>
                                        <option <?php if($guests == 6) echo 'selected="selected"'; ?>>6</option>
                                        <option <?php if($guests == 7) echo 'selected="selected"'; ?>>7</option>
                                        <option <?php if($guests == 8) echo 'selected="selected"'; ?>>8</option>
                                        <option <?php if($guests == 9) echo 'selected="selected"'; ?>>9</option>
                                        <option <?php if($guests == 10) echo 'selected="selected"'; ?>>10</option>
                                        <option <?php if($guests == 11) echo 'selected="selected"'; ?>>11</option>
                                        <option <?php if($guests == 12) echo 'selected="selected"'; ?>>12</option>
                                        <option <?php if($guests == 13) echo 'selected="selected"'; ?>>13</option>
                                        <option <?php if($guests == 14) echo 'selected="selected"'; ?>>14</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <button class="btn btn-primary btn-lg" type="submit" name="search">Search for Hotels</button>
                </form>
            </div>
            <h3 class="booking-title"><?php echo count($hotelsearch);?> hotels found that can accomondate <?php echo $guests; ?> guests</h3>
            <div class="row">
                <div class="col-md-3">
                    <form action="" method="get" class="booking-item-dates-change mb30">
                        <div class="form-group form-group-icon-left"><i class="fa fa-map-marker input-icon input-icon-hightlight"></i>
                            <label>Where</label>
                            <input class="typeahead form-control" value="<?php if(isset($address_city_name)){ echo $address_city_name;}else echo 'Address,City,Name'?>" type="text" name="address" />
                        </div>
                        <div class="input-daterange" data-date-format="dd/mm/yyyy">
                            <div class="form-group form-group-icon-left"><i class="fa fa-calendar input-icon input-icon-hightlight"></i>
                                <label>Check in</label>
                                <input class="form-control"  value="<?php if(isset($checkin)){echo $getcheckin;} else echo "" ;?>" name="start" type="text" />
                            </div>
                            <div class="form-group form-group-icon-left"><i class="fa fa-calendar input-icon input-icon-hightlight"></i>
                                <label>Check out</label>
                                <input class="form-control" value="<?php if(isset($checkout)){echo $getcheckout;} else echo "" ;?>" name="end" type="text" />
                            </div>
                        </div>
                        <div class="form-group form-group- form-group-select-plus">
                            <label>Guests</label>
                            <div class="btn-group btn-group-select-num" data-toggle="buttons">
                                <label class="btn btn-primary <?php if($guests == 1) echo 'active'; ?>">
                                    <input type="radio" name="guests" value="1" <?php if($guests == 1) echo 'checked'; ?> />1</label>
                                <label class="btn btn-primary <?php if($guests == 2) echo 'active'; ?>">
                                    <input type="radio" name="guests" value="2" <?php if($guests == 2) echo 'checked'; ?> />2</label>
                                <label class="btn btn-primary <?php if($guests == 3) echo 'active'; ?>">
                                    <input type="radio" name="guests" value="3" <?php if($guests == 3) echo 'checked'; ?> />3</label>
                                <label class="btn btn-primary <?php if($guests == 4) echo 'active'; ?>">
                                    <input type="radio" name="guests" value="4" <?php if($guests == 4) echo 'checked'; ?> />4</label>
                                <label class="btn btn-primary <?php if($guests > 4) echo 'active'; ?>">
                                    <input type="radio" name="guests" value="4+" />4+</label>
                            </div>
                            <select class="form-control hidden" name="guests_list">
                                <option <?php if($guests == 1) echo 'selected="selected"'; ?>>1</option>
                                <option <?php if($guests == 2) echo 'selected="selected"'; ?>>2</option>
                                <option <?php if($guests == 3) echo 'selected="selected"'; ?>>3</option>
                                <option <?php if($guests == 4) echo 'selected="selected"'; ?>>4</option>
                                <option <?php if($guests == 5) echo 'selected="selected"'; ?>>5</option>
                                <option <?php if($guests == 6) echo 'selected="selected"'; ?>>6</option>
                                <option <?php if($guests == 7) echo 'selected="selected"'; ?>>7</option>
                                <option <?php if($guests == 8) echo 'selected="selected"'; ?>>8</option>
                                <option <?php if($guests == 9) echo 'selected="selected"'; ?>>9</option>
                                <option <?php if($guests == 10) echo 'selected="selected"'; ?>>10</option>
                                <option <?php if($guests == 11) echo 'selected="selected"'; ?>>11</option>
                                <option <?php if($guests == 12) echo 'selected="selected"'; ?>>12</option>
                                <option <?php if($guests == 13) echo 'selected="selected"'; ?>>13</option>
                                <option <?php if($guests == 14) echo 'selected="selected"'; ?>>14</option>
                            </select>
                        </div>
                       
                        <input class="btn btn-primary" type="submit" value="Update Search" name="search" />
                    </form>
                        </div>
                <div class="col-md-9">
                    <ul class="booking-list">
                         <?php


                            if($hotelsearch):
                            foreach($hotelsearch as $hotelid):
                            $hotelentry=getHotelDetails($hotelid['ID']);
                          ?>
                        <li>
                            <a class="booking-item" href="hotel.php?id=<?php echo $hotelentry['hotelID']; ?>&start=<?php echo $getcheckin;?>&end=<?php echo  $getcheckout; ?>&guests=<?php echo $guests; ?>&check=1">
                                <div class="row">
                                    <div class="col-md-3">
                                        <div class="booking-item-img-wrap">
                                                <!-- εμφανίζει την πρώτη φωτογραφία -->
                                                <?php
                                                                $photos = unserialize($hotelentry['hotelPhotos']);
                                                        if($photos):
                                                                $photo = $photos[0];
                                                        endif;
                                                ?>
                                                                                        <img src="<?php echo MEDIA.$photo; ?>" alt="hotel thumbnail" />
                                                <div class="booking-item-img-num"><i class="fa fa-picture-o"></i><?php echo count($photos);?></div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="booking-item-rating">
                                            <ul class="icon-group booking-item-rating-stars">
                                                <!-- εμφανίζει τα αστέρια -->
                                                <?php
                                                        $stars = $hotelentry['hotelStars'];
                                                        for($i=0; $i<$stars; $i++){
                                                        echo '<li><i class="fa fa-star"></i></li>';
                                                }
                                                ?>
                                            </ul><span class="booking-item-rating-number"> </span><!-- hotel stars-->
                                        </div>
                                        <h5 class="booking-item-title"><?php echo $hotelentry['hotelName']; ?></h5>
                                        <p class="booking-item-address"><i class="fa fa-map-marker"></i>&nbsp;<?php echo $hotelentry['hotelCity']; ?> </p>
                                       <small class="booking-item-last-booked"><?php echo $hotelentry['hotelCountry']; ?></small>
                                       </div>
                                       <div class="col-md-3"><span class="booking-item-price-from">from</span><span class="booking-item-price">€<?php echo getsmallerprice($hotelentry['hotelID']); ?></span><span>/night</span></br><span class="btn btn-primary">View Hotel</span>
                                </div>

                                </div>
                            </a>
                        </li>
                     <?php
                          endforeach;
                          endif;
                     ?>

                                        </ul>
                    <div class="row">
                        <div class="col-md-6 text-right">
                            <p>Not what you're looking for? <a class="popup-text" href="#search-dialog" data-effect="mfp-zoom-out">Try your search again</a>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="gap"></div>
        </div>
       

        <footer id="main-footer">
            <div class="container">
                <div class="row row-wrap">
                    <div class="col-md-3">
                        <a class="logo" href="index.php">
                            <img src="assets/img/logo-invert.png" alt="Image Alternative text" title="Image Title" />
                        </a>
                        <p class="mb20">Booking, reviews and advices on hotels and lots more!</p>
                        <ul class="list list-horizontal list-space">
                            <li>
                                <a class="fa fa-facebook box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                            </li>
                            <li>
                                <a class="fa fa-twitter box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                            </li>
                            <li>
                                <a class="fa fa-google-plus box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                            </li>
                            <li>
                                <a class="fa fa-linkedin box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                            </li>
                            <li>
                                <a class="fa fa-pinterest box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                            </li>
                        </ul>
                    </div>
                    <div class="col-md-4">
                        <h4>Have Questions?</h4>
                        <h5><a href="#" class="text-color">al.s.katsaros@gmail.com</a></h5>
                        <h5><a href="#" class="text-color">cskostas@gmail.com</a></h5>
                        <h5><a href="#" class="text-color">g.gravanis@gmail.com</a></h5>
                        <h5><a href="#" class="text-color">grgstoupas@gmail.com</a></h5>
                        <p>24/7 Dedicated Customer Support</p>
                    </div>
                    <div id="project-details" class="col-md-5">
                        <h4>This is an experimental project</h4>
                        <h5 class="text-color">based on "Software Engineering for Web Applications" course of "Master of Science (MSc) in Web Intelligence"</h5>
                        <a href="http://msc.it.teithe.gr/" target="_blank"><img src="assets/img/logo-swk-final-s.png" alt="" style="width:80%;" /></a>
                    </div>
                </div>
            </div>
        </footer>

        <script src="assets/js/jquery.js"></script>
        <script src="assets/js/bootstrap.js"></script>
        <script src="assets/js/slimmenu.js"></script>
        <script src="assets/js/bootstrap-datepicker.js"></script>
        <script src="assets/js/bootstrap-timepicker.js"></script>
        <script src="assets/js/nicescroll.js"></script>
        <script src="assets/js/dropit.js"></script>
        <script src="assets/js/ionrangeslider.js"></script>
        <script src="assets/js/icheck.js"></script>
        <script src="assets/js/fotorama.js"></script>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
        <script src="assets/js/typeahead.js"></script>
        <script src="assets/js/card-payment.js"></script>
        <script src="assets/js/magnific.js"></script>
        <script src="assets/js/owl-carousel.js"></script>
        <script src="assets/js/fitvids.js"></script>
        <script src="assets/js/tweet.js"></script>
        <script src="assets/js/countdown.js"></script>
        <script src="assets/js/gridrotator.js"></script>
        <script src="assets/js/custom.js"></script>
    </div>
  </div>
</body>

</html>